from common import *

import numpy

default_data = {'stumps':1, 'axis':0}

def setup(data = default_data):
    import wx
    dlg = wx.TextEntryDialog(
        None, 'Number of stumps',
        'Configure Process', str(data['stumps']))
    if dlg.ShowModal() == wx.ID_OK:
        data['stumps'] = int(dlg.GetValue())
    dlg.Destroy()

    dlg = wx.TextEntryDialog(
        None, 'Collect over axis',
        'Configure Process', str(data['axis']))
    if dlg.ShowModal() == wx.ID_OK:
        data['axis'] = int(dlg.GetValue())
    dlg.Destroy()
    return data


def CollectArrayFunc(in0,out0 , data = default_data):
    while True:
        stumps = {}
        
        while (len(stumps) != data['stumps']):
            (job_id, stump) = in0()
            stumps[job_id] = stump
        
        if (len(stumps) > 1):
            array = numpy.concatenate(stumps.values(), axis=data['axis'])
        else:
            array = stumps[1]
            
        out0(array)    


